home *** CD-ROM | disk | FTP | other *** search
-
- //=================================================================
- // CommandCodeTrigger
- // See CommandCodeTrigger.txt
- //=================================================================
- class CommandCodeTrigger extends Trigger placeable;
-
- // data members for messages and random numbers
- var private string FirstMessage;
- var private string CodeForSearch;
- const NUMOFMESSAGES = 6;
- enum PState{
- UP,
- DOWN
- };
- // #1
- const CODELENGTH = 8;
- const NUMOFTRIES = 20;
- const LOWASCII = 97;
- const HIGHASCII = 122;
-
- function PostBeginPlay()
- {
- FirstMessage = "Go!";
- Super.PostBeginPlay();
- Message = FirstMessage;
- // #2
- CodeForSearch = MakeCode(CODELENGTH);
- }// end PostBeginPlay()
-
- function Touch( actor Other )
- {
- if (IsRelevant( Other ) )
- {
- if (Pawn(Other).bIsCrouched){ // down state
- Message= MakeMessage(PState.DOWN);
- }// end if
- else{ // up state
- Message= MakeMessage(PState.UP);
- }// end else
-
- Super.Touch(Other);
- }// end outer if
- }// end Touch()
-
- private function string MakeMessage(PState state){
- local int RandomNumber;
- local string ActionMessage;
- RandomNumber = Rand(NUMOFMESSAGES);
-
- // Build messages on the basis of up or down state
-
- if( state == PState.UP ){
- ActionMessage @= "Get down! ";
-
- // #3
- // Reveal the code
- ActionMessage @= "Here is the code: ";
- ActionMessage @= GetCodeForSearch();
- }
- else if( state == PState.DOWN ){
- ActionMessage @= "Get up! - ";
- // Convey a message
- ActionMessage @= GetMessageText(RandomNumber);
- // find a letter of the code
- // #4
- ActionMessage @= ReportCodeFound( CodeForSearch );
- }
- else {
- ActionMessage = "Okay.";
- }
- return ActionMessage;
- }
-
- private function string GetMessageText(int index){
- // Define a static array of the string type
- local string PawnMessages[NUMOFMESSAGES];
- local string TMessage;
- // Assign text values to elements
- PawnMessages[0]= "Watch out behind you!";
- PawnMessages[1]= "Turn to your left!";
- PawnMessages[2]= "Get ready to go!";
- PawnMessages[3]= "Did you see the danger?";
- PawnMessages[4]= "Can we move again?";
- PawnMessages[5]= "How many did you see?";
- // Retrieve an element from the array
- if(index < NUMOFMESSAGES && index >= 0){
- TMessage = PawnMessages[index];
- }
- return TMessage;
- }
-
- private function string MakeCode(int limit){
- local int Ctr;
- local string Code;
- // Control for the while statement
- Ctr = 0;
- // #5
- while(Ctr < limit){
- // Build a sting using random numbers
- // Convert the numbers to letters
- Code $= Chr(GenerateRandom());
- // Increment the count
- Ctr++;
- }// end while
- return Code;
- }// end MakeCode
-
- // #6
- private function int GenerateRandom(){
- local float high, low;
- Low = LOWASCII;
- High = HIGHASCII;
- // Return an integer
- return Int( RandRange( Low , High ));
- }
-
- // #7
- private function string GetCodeForSearch(){
- return CodeForSearch;
- }
-
- private function string ReportCodeFound(string Code){
- local string SelectedLetter, Report;
- local int Ctr;
-
- // #8
- for(Ctr = 0; Ctr < NUMOFTRIES; Ctr++){
- // Cast numbers to a string
- SelectedLetter = Chr(GenerateRandom());
- // See if it is in the string
- // #9
- // Use compound Boolean to determine if
- // the letter is in the code range
- if( InStr(Code, SelectedLetter) >= 0
- && InStr(Code, SelectedLetter) <= CODELENGTH){
- Report @= "Okay, you have found part of the code: ";
- // Add the letter to the report
- Report @= SelectedLetter;
- break;
- }// end if
- }// end for
- return Report;
- }
-